package com.ying.controller;

import com.ying.domain.UserOne;
import com.ying.domain.UserTwo;
import com.ying.service.impl.TxService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liujunjie
 * @Description description
 * @Date 2024-10-08 18:20
 **/
@RestController
@RequestMapping("/tx")
@Tag(name = "事务管理")
public class TxController {
    @Autowired
    private TxService txService;

    @GetMapping("/requiedAndrequired")
    @Operation(summary = "requied_required")
    public void requiedAndrequired() {
        UserOne userOne= new UserOne();
        userOne.setName("小红");
        UserTwo userTwo= new UserTwo();
        userTwo.setName("小明");
        txService.requiedAndrequired(userOne,userTwo);
    }

    @GetMapping("/requiedAndrequiredException")
    @Operation(summary = "requied_requiredException")
    public void requiedAndrequiredException() {
        UserOne userOne= new UserOne();
        userOne.setName("小红");
        UserTwo userTwo= new UserTwo();
        userTwo.setName("小明");
        txService.requiedAndrequiredExcepection(userOne,userTwo);
    }
    @GetMapping("/notransaction_exception_required_required")
    @Operation(summary = "无事务，外围报错，内部不报错")
    public void notransaction_exception_required_required() {
        UserOne userOne= new UserOne();
        userOne.setName("小红");
        UserTwo userTwo= new UserTwo();
        userTwo.setName("小明");
        txService.notransaction_exception_required_required(userOne,userTwo);
    }

    @GetMapping("/transaction_exception_required_required")
    @Operation(summary = "外围有事务且报错，内部2个required")
    public void transaction_exception_required_required() {
        UserOne userOne= new UserOne();
        userOne.setName("小红");
        UserTwo userTwo= new UserTwo();
        userTwo.setName("小明");
        txService.transaction_exception_required_required(userOne,userTwo);
    }

    @GetMapping("/commonTest")
    public void commonTest() {
        UserOne userOne= new UserOne();
        userOne.setName("小红");
        UserTwo userTwo= new UserTwo();
        userTwo.setName("小明");
        txService.commonTest(userOne,userTwo);
    }



}
